import { useEffect, useState } from 'react';

import { BusinessAPI } from '@/api/reworkAPI';

// Define the return type of our hook
interface UseHomeReturn {
  title: string;
  celebrityData: Face.Celebrity[];
  templateData: Face.Template[];
  activeCategory: string;
  setActiveCategory: (category: string) => void;
}

const useHome = (): UseHomeReturn => {
  const [activeCategory, setActiveCategory] = useState<string>('All');

  // In a real app, you would fetch this data from an API
  // const celebrityData = mockCelebrityData;
  const [templateData, setTemplateData] = useState<Face.Template[]>([]);
  const [celebrityData, setCelebrityData] = useState<Face.Celebrity[]>([]);

  useEffect(() => {
    // 获取人物模版
    BusinessAPI.getTemplates().then((res) => {
      if (res.code == 0) {
        const data = res.data;
        if (data.records) {
          // setTemplateData(data.records);
          setCelebrityData(data.records);
        }
      } else {
        console.log('start======================');
        console.log('我来这了111');
        console.log('end========================');
      }
    });
  }, []);

  useEffect(() => {
    BusinessAPI.getTopicTemplates().then((res) => {
      if (res.code == 0) {
        const data = res.data;
        if (data.records) {
          setTemplateData(data.records);
        }
      } else {
        console.log('start======================');
        console.log('我来这了');
        console.log('end========================');
      }
    });
  }, []);

  return {
    title: 'Explore',
    celebrityData,
    templateData,
    activeCategory,
    setActiveCategory,
  };
};

export default useHome;
